#ifndef ROAD_H_
#define ROAD_H_

#include <vector>
#include <string>
#include <stdint.h>
#include "Geo.h"
#include "MapTiles.h"

namespace opennav {

struct RoadHeader {
	int32_t road_def_index_table_offset;
	int32_t road_def_index_table_size;
	int32_t road_def_table_offset;
	int32_t segment_table_offset;
	int32_t junction_table_offset;
};

enum RoadType {
	ROAD_Motorway = 0,
	ROAD_Type1 = 1,
	ROAD_Type2 = 2,
	ROAD_Type3 = 3,
	ROAD_Type4 = 4,
	ROAD_Type5 = 5,
	ROAD_Track = 6,
};

struct Road {
	int32_t road_id;
	std::vector<std::string> labels;
	int32_t city_id;
	int32_t segments_offset;
};

struct RoadJunction {
	int32_t offset;
	Coordinate coordinate;
	std::vector<int32_t> segment_offsets;
};

struct RoadSegment {
	int32_t offset;
	RoadType type;
	bool oneway;
	bool backward;
	bool toll;
	bool last;
	int32_t road_id;
	int32_t junction_from_offset;
	int32_t junction_to_offset;
	uint8_t maxspeed;
	uint16_t length;
	std::vector<MapObjectReference> map_object_refs;

	uint8_t get_max_speed() const {
		if (maxspeed > 0)
			return maxspeed;
		switch (type) {
		case ROAD_Motorway:
			return 130;
		case ROAD_Type1:
			return 100;
		case ROAD_Type2:
			return 80;
		case ROAD_Type3:
			return 60;
		case ROAD_Type4:
			return 50;
		case ROAD_Type5:
			return 60;
		case ROAD_Track:
			return 5;
		default:
			return 1;
		}
	}

	bool operator==(const RoadSegment& c) const	{
		return offset == c.offset;
	}
};

}

#endif
